import 'package:flutter/material.dart';
import 'package:woandroid/pages/BaseState.dart';
import 'package:woandroid/pages/ArticleListPage.dart';

class ArticlesPage extends StatefulWidget{
  var data;
  ArticlesPage(this.data);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new ArticlesPageState();
  }
}
class ArticlesPageState extends BaseState<ArticlesPage> with SingleTickerProviderStateMixin{
  TabController _controller;
  List<Tab> tabs=new List();
  List<dynamic> list;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    list=widget.data['children'];
    for(var v in list){
      tabs.add(new Tab(text: v['name'],));
    }
    _controller=new TabController(length: list.length, vsync: this);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    return new Scaffold(
      appBar: AppBar(title: Text(widget.data['name']),),
      body: DefaultTabController(length: list.length, child: Scaffold(
        appBar: TabBar(
          tabs: tabs,
          isScrollable: true,
          controller: _controller,
          labelColor: Colors.cyan,
          indicatorColor: Colors.cyan,
          unselectedLabelColor: Colors.black,
          indicatorPadding: EdgeInsets.only(right: 4),
          indicatorSize: TabBarIndicatorSize.label,
        ),
        body: TabBarView(
            controller: _controller,
            children: list.map((dynamic data){
              return new ArticleListPage(data['id'].toString());
            }).toList()),
      )),

    );

  }
}